package com.genesis.web.controller;


import com.genesis.mall.common.PageInfo;
import com.genesis.mall.common.Result;
import com.genesis.mall.service.ISmsCouponService;
import com.genesis.mall.vo.SmsCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 优惠券表 前端控制器
 * </p>
 *
 * @author author
 * @since 2022-08-01
 */
@RestController
@RequestMapping("/coupon")
public class SmsCouponController {

    @Autowired
    private ISmsCouponService couponService;

    /**
     * 添加优惠券
     * @param couponVo
     * @return
     */
    @PostMapping("/create")
    private Result createCoupon(@RequestBody SmsCouponVo couponVo){
        couponService.createCoupon(couponVo);
        return Result.success();
    }


    /**
     * 删除优惠券
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public Result deleteCoupon(@PathVariable Integer id){
        couponService.deleteCoupon(id);
        return Result.success();
    }


    /**
     * 根据优惠券名称和类型分页获取优惠券列表
     * @param name
     * @param pageNum
     * @param pageSize
     * @param type
     * @return
     */
    @GetMapping("/list")
    public Result listCoupon(@RequestParam(required = false) String name,@RequestParam(required = false) Integer pageNum,
                        @RequestParam(required = false) Integer pageSize,@RequestParam(required = false) Integer type){
        PageInfo pageInfo = couponService.listCoupon(name,pageNum,pageSize,type);
        return Result.success(pageInfo);
    }


    /**
     * 修改优惠券
     * @param couponVo
     * @param id
     * @return
     */
    @PostMapping("/update/{id}")
    public Result updateCoupon(@RequestBody SmsCouponVo couponVo, @PathVariable Integer id){
        couponService.updateCoupon(couponVo,id);
        return Result.success();
    }

    /**
     * 获取单个优惠券的详细信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getOneCoupon(@PathVariable Integer id){
        SmsCouponVo couponVo = couponService.getOneCoupon(id);
        return Result.success(couponVo);
    }


}
